unit USistema;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFomCadastro, StdCtrls, Buttons, ExtCtrls, DB, DBTables, RxCalc,
  ToolEdit, Mask, DBCtrls, DBClient, Provider, Menus, ComCtrls, Grids,
  DBGrids;

type
  TFCadastroSistema = class(TFormCadastro)
    DSSistema: TDataSource;
    QSistema: TQuery;
    DEBackup: TDirectoryEdit;
    DEBase: TDirectoryEdit;
    FENomeBase: TFilenameEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBCBImagemVisivel: TDBCheckBox;
    FEDirImagem: TFilenameEdit;
    Label5: TLabel;
    DEDirExecutavel: TDirectoryEdit;
    cbBackupFechamento: TDBCheckBox;
    procedure BtnEditarClick(Sender: TObject);
    procedure BtnExcluirClick(Sender: TObject);
    procedure BtnSalvarClick(Sender: TObject);
    procedure BtnCancelarClick(Sender: TObject);
    procedure QSistemaAfterOpen(DataSet: TDataSet);
    procedure QSistemaBeforePost(DataSet: TDataSet);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FCadastroSistema: TFCadastroSistema;

implementation

{$R *.dfm}

procedure TFCadastroSistema.BtnEditarClick(Sender: TObject);
begin
  inherited;
 if QSistema.IsEmpty then
  QSistema.Append
 else
  QSistema.Edit; 

end;

procedure TFCadastroSistema.BtnExcluirClick(Sender: TObject);
begin
  inherited;
 if QSistema.IsEmpty then
  exit;
 if MessageDlg('Deseja realmente excluir este registro ? ',mtWarning,mbOKCancel,0) = 2 then
  exit;
 QSistema.Delete;
end;

procedure TFCadastroSistema.BtnSalvarClick(Sender: TObject);
begin
  inherited;
 QSistema.Post;
end;

procedure TFCadastroSistema.BtnCancelarClick(Sender: TObject);
begin
  inherited;
 QSistema.Cancel;
end;

procedure TFCadastroSistema.QSistemaAfterOpen(DataSet: TDataSet);
begin
  inherited;
 DEDirExecutavel.Text:=QSistema.fieldByname('SIS_DIREXE').AsString;
 DEBackup.Text:=QSistema.fieldByname('SIS_DIRBACKUP').AsString;
 DEBase.Text:=QSistema.fieldByname('SIS_DIRBASE').AsString;
 FENomeBase.Text:=QSistema.fieldByname('SIS_NOMEBASE').AsString;
 FENomeBase.InitialDir:=QSistema.fieldByname('SIS_DIRBASE').AsString;
 FEDirImagem.Text:=QSistema.fieldByname('SIS_DIRImagem').AsString;

end;

procedure TFCadastroSistema.QSistemaBeforePost(DataSet: TDataSet);
begin
  inherited;
 QSistema.fieldByname('SIS_DIREXE').AsString:=DEDirExecutavel.Text;
 QSistema.fieldByname('SIS_DIRBACKUP').AsString:=DEBackup.Text;
 QSistema.fieldByname('SIS_DIRBASE').AsString:=DEBase.Text;
 QSistema.fieldByname('SIS_NOMEBASE').AsString:=FENomeBase.Text;
 QSistema.fieldByname('SIS_DIRImagem').AsString:=FEDirImagem.Text;
end;

procedure TFCadastroSistema.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 FCadastroSistema:=nil;
  inherited;
end;

procedure TFCadastroSistema.FormCreate(Sender: TObject);
begin
  inherited;
 QSistema.close;
 QSistema.open;
end;

end.
